//
// Created on 24/7/31.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef MOONLIGHTOH_CERTIFICATEENVIRONMENT_H
#define MOONLIGHTOH_CERTIFICATEENVIRONMENT_H

#include <mutex>
#include <string>
#include <optional>
#include <filesystem>

class CertificateEnvironment {
public:
    /**
     * Load (or generate if not already exists) certificate from storage.
     * @param force_renew Force renewal of new certificate.
     */
    static void load(bool force_renew = false);
    
    static std::filesystem::path get_cert_path();
    static std::filesystem::path get_p12_path();
    static std::filesystem::path get_keypair_path();
    
public:
    static inline const std::string CERT_FILENAME = "client.pem";
    static inline const std::string P12_FILENAME = "client.p12";
    static inline const std::string KEY_PAIR_FILENAME = "key.pem";
    
private:
    static inline std::recursive_mutex _mtx;
    static inline std::optional<std::filesystem::path> _cert_dir = std::nullopt;
};

#endif //MOONLIGHTOH_CERTIFICATEENVIRONMENT_H
